﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SimpleTemplatedControl : System.Web.UI.UserControl
{
    private ITemplate messageTemplate = null;

    [TemplateContainer(typeof(MessageContainer))]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public ITemplate MessageTemplate
    {
        get
        {
            return messageTemplate;
        }
        set
        {
            messageTemplate = value;
        }
    }
    protected void Page_Init()
    {
        if (messageTemplate != null)
        {
            String[] fruits = { "apple", "orange", "banana", "pineapple" };
            for (int i = 0; i < 4; i++)
            {
                MessageContainer container = new MessageContainer(i, fruits[i]);
                messageTemplate.InstantiateIn(container);
                PlaceHolder1.Controls.Add(container);
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.DataBind();
    }
}
